﻿using System.Collections.Generic;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Sunny.Entity;
using Sunny.Model.RequestParam;
using Sunny.Service;
using Sunny.Util.Attributes;
using Sunny.Util.Enums;

namespace Sunny.Api.Controllers
{
    [ApiController]
    [Route("/system/operlog")]
    public class SysOperateLogController
    {
        private readonly OperateLogService _operateLogService;

        public SysOperateLogController(OperateLogService operateLogService)
        {
            _operateLogService = operateLogService;
        }

        #region 查询操作日志列表
        [HasPermission("monitor:operlog:list")]
        [HttpGet("list")]
        public async Task<Result> List([FromQuery]OperateLogListParam param)
        {
            (List<SysOperLog> logs,int total) = await _operateLogService.List(param);
            return Result.Success(new
            {
                rows = logs,total
            });
        }

        #endregion

        #region 批量删除日志
        [HasPermission("monitor:operlog:remove")]
        [LogInfo(Title = "操作日志管理",BusinessType = BusinessType.Delete)]
        [HttpDelete("{logIds}")]
        public async Task<Result> BatchDelete([FromRoute]string logIds)
        {
            await _operateLogService.BatchDelete(logIds);
            return Result.Success();
        }

        #endregion
        
        #region 清除日志
        [HasPermission("monitor:operlog:remove")]
        [LogInfo(Title = "操作日志管理",BusinessType = BusinessType.Delete)]
        [HttpDelete("clean")]
        public async Task<Result> DeleteAll()
        {
            await _operateLogService.DeleteAll();
            return Result.Success();
        }

        #endregion
    }
}